package com.fw.ui.view.settings.usercontrol.bouser;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.fw.service.bean.EntryBean;
import com.fw.service.bean.SearchCriteriaBean;
import com.fw.service.bean.SearchResultBean;
import com.fw.service.bouser.bean.BOUserBean;
import com.fw.service.bouser.bean.SearchBOUserBean;
import com.fw.ui.bao.BOUserBAO;
import com.fw.ui.bao.MasterDataBAO;
import com.fw.ui.bao.MessageBAO;
import com.fw.ui.bao.PropertyBAO;
import com.fw.ui.bean.bouser.SearchBOUserTableItemBean;
import com.fw.ui.core.ViewDescription;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.AbstractView;
import com.fw.ui.view.common.SortingTablePanel;
import com.fw.ui.view.common.TablePanel;
import com.fw.ui.view.common.util.TableHeaderProperty;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserClearButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserNewButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserSearchButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTableDeleteButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTableEditButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTablePageButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTableSizeValueChangeListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTableSortButtonClickListener;
import com.fw.ui.view.settings.usercontrol.bouser.event.SearchBOUserTableViewButtonClickListener;
import com.fw.util.StringUtils;
import com.vaadin.data.util.BeanItem;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.Table.Align;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

@org.springframework.stereotype.Component
@Scope(SCOPE_PROTOTYPE)
@ViewDescription(name = "settings-user-control-bouser-search", path = "/settings/user-control/bouser-search")
public class SearchBOUserView extends AbstractView {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;

    @Autowired
    private MasterDataBAO masterDataBAO;
    @Autowired
    private MessageBAO messageBAO;
    @Autowired
    private PropertyBAO propertyBAO;
    @Autowired
    private BOUserBAO boUserBAO;

    private Map<String, String> statusMap = new HashMap<String, String>();
    private SearchBOUserBean searchBOUserBean = new SearchBOUserBean();
    private SearchCriteriaBean<SearchBOUserBean> searchCriteriaBean = new SearchCriteriaBean<SearchBOUserBean>();

    @Autowired
    private SearchBOUserClearButtonClickListener searchBOUserClearButtonClickListener;
    @Autowired
    private SearchBOUserNewButtonClickListener searchBOUserNewButtonClickListener;
    @Autowired
    private SearchBOUserSearchButtonClickListener searchBOUserSearchButtonClickListener;
    @Autowired
    private SearchBOUserTableDeleteButtonClickListener searchBOUserTableDeleteButtonClickListener;
    @Autowired
    private SearchBOUserTableEditButtonClickListener searchBOUserTableEditButtonClickListener;
    @Autowired
    private SearchBOUserTablePageButtonClickListener searchBOUserTablePageButtonClickListener;
    @Autowired
    private SearchBOUserTableSizeValueChangeListener searchBOUserTableSizeValueChangeListener;
    @Autowired
    private SearchBOUserTableSortButtonClickListener searchBOUserTableSortButtonClickListener;
    @Autowired
    private SearchBOUserTableViewButtonClickListener searchBOUserTableViewButtonClickListener;

    /**
     * COMPONENT
     */
    private Panel searchBOUserPanel = new Panel();

    @Autowired
    protected TablePanel tablePanel;
    @Autowired
    protected SortingTablePanel sortingTablePanel;

    private Label lblUsername = new Label();
    private Label lblEmployeeId = new Label();
    private Label lblEmployeeName = new Label();
    private Label lblEmailAddress = new Label();
    private Label lblGroup = new Label();
    private Label lblExpireDate = new Label();
    private Label lblExpireDateFrom = new Label();
    private Label lblExpireDateTo = new Label();
    private Label lblStatus = new Label();
    private Label lblCreateDate = new Label();
    private Label lblCreateDateFrom = new Label();
    private Label lblCreateDateTo = new Label();
    private Label lblCreateBy = new Label();
    private Label lblLastUpdateDate = new Label();
    private Label lblLastUpdateDateFrom = new Label();
    private Label lblLastUpdateDateTo = new Label();
    private Label lblLastUpdateBy = new Label();

    private ComboBox cbbUsername = new ComboBox();
    private ComboBox cbbEmployeeId = new ComboBox();
    private ComboBox cbbEmployeeName = new ComboBox();
    private ComboBox cbbCreateBy = new ComboBox();
    private ComboBox cbbLastUpdateBy = new ComboBox();
    private ComboBox cbbGroup = new ComboBox();
    private ComboBox cbbStatus = new ComboBox();

    private TextField txtEmailAddress = new TextField();

    private PopupDateField pdfExpireDateFrom = new PopupDateField();
    private PopupDateField pdfExpireDateTo = new PopupDateField();
    private PopupDateField pdfCreateDateFrom = new PopupDateField();
    private PopupDateField pdfCreateDateTo = new PopupDateField();
    private PopupDateField pdfLastUpdateDateFrom = new PopupDateField();
    private PopupDateField pdfLastUpdateDateTo = new PopupDateField();

    private Button btnSearch = new Button();
    private Button btnNew = new Button();
    private Button btnClear = new Button();

    private TableHeaderProperty hUsername = new TableHeaderProperty();
    private TableHeaderProperty hEmployeeId = new TableHeaderProperty();
    private TableHeaderProperty hEmployeeName = new TableHeaderProperty();
    private TableHeaderProperty hEmailAddress = new TableHeaderProperty();
    private TableHeaderProperty hGroup = new TableHeaderProperty();
    private TableHeaderProperty hExpireDate = new TableHeaderProperty();
    private TableHeaderProperty hStatus = new TableHeaderProperty();
    private TableHeaderProperty hCreateDate = new TableHeaderProperty();
    private TableHeaderProperty hCreateBy = new TableHeaderProperty();
    private TableHeaderProperty hLastUpdateDate = new TableHeaderProperty();
    private TableHeaderProperty hLastUpdateBy = new TableHeaderProperty();
    private TableHeaderProperty hCommand = new TableHeaderProperty();

    private List<Button> tableViewButtons = new ArrayList<Button>();
    private List<Button> tableEditButtons = new ArrayList<Button>();
    private List<Button> tableDeleteButtons = new ArrayList<Button>();

    @Override
    public void updateStrings() {
	this.searchBOUserPanel.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.title"));

	this.lblUsername.setValue(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.username"));
	this.lblEmailAddress
		.setValue(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.email"));
	this.lblEmployeeId.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.employee.id"));
	this.lblEmployeeName.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.employee.name"));
	this.lblGroup.setValue(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.group"));
	this.lblStatus.setValue(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.status"));
	this.lblCreateBy.setValue(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.createby"));
	this.lblLastUpdateBy.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.lastupdateby"));
	this.lblExpireDate.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.expiredate"));
	this.lblExpireDateFrom.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.expiredate.from"));
	this.lblExpireDateTo.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.expiredate.to"));
	this.lblCreateDate.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.createdate"));
	this.lblCreateDateFrom.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.createdate.from"));
	this.lblCreateDateTo.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.createdate.to"));
	this.lblLastUpdateDate.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.lastupdatedate"));
	this.lblLastUpdateDateFrom.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.lastupdatedate.from"));
	this.lblLastUpdateDateTo.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.label.lastupdatedate.to"));

	this.cbbUsername.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.username"));
	this.txtEmailAddress.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.email"));
	this.cbbEmployeeId.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.employee.id"));
	this.cbbEmployeeName.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.employee.name"));
	this.cbbGroup.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.group"));
	this.cbbStatus.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.status"));
	this.cbbCreateBy.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.createby"));
	this.cbbLastUpdateBy.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.lastupdateby"));
	this.pdfExpireDateFrom.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.expiredate.from"));
	this.pdfExpireDateTo.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.expiredate.to"));
	this.pdfCreateDateFrom.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.createdate.from"));
	this.pdfCreateDateTo.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.createdate.to"));
	this.pdfLastUpdateDateFrom.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.lastupdatedate.from"));
	this.pdfLastUpdateDateTo.setInputPrompt(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.inputprompt.lastupdatedate.to"));

	this.btnSearch.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.search"));
	this.btnNew.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.new"));
	this.btnClear.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.clear"));

	this.hUsername.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.username"));
	this.hEmployeeId.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.employeeid"));
	this.hEmployeeName.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.employeeName"));
	this.hEmailAddress.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.emailAddress"));
	this.hLastUpdateDate.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.lastUpdateDate"));
	this.hLastUpdateBy.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.lastUpdateBy"));
	this.hCreateBy.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.createBy"));
	this.hCreateDate.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.createDate"));
	this.hStatus.setColumnName(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.status"));
	this.hGroup.setColumnName(this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.group"));
	this.hExpireDate.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.expireDate"));
	this.hCommand.setColumnName(this.messageBAO
		.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.header.command"));

	tablePanel.setTableColumnHeader(this.hUsername.getColumnId(), this.hUsername.getColumnName());
	tablePanel.setTableColumnHeader(this.hEmployeeId.getColumnId(), this.hEmployeeId.getColumnName());
	tablePanel.setTableColumnHeader(this.hEmployeeName.getColumnId(), this.hEmployeeName.getColumnName());
	tablePanel.setTableColumnHeader(this.hEmailAddress.getColumnId(), this.hEmailAddress.getColumnName());
	tablePanel.setTableColumnHeader(this.hLastUpdateDate.getColumnId(), this.hLastUpdateDate.getColumnName());
	tablePanel.setTableColumnHeader(this.hLastUpdateBy.getColumnId(), this.hLastUpdateBy.getColumnName());
	tablePanel.setTableColumnHeader(this.hCreateBy.getColumnId(), this.hCreateBy.getColumnName());
	tablePanel.setTableColumnHeader(this.hCreateDate.getColumnId(), this.hCreateDate.getColumnName());
	tablePanel.setTableColumnHeader(this.hStatus.getColumnId(), this.hStatus.getColumnName());
	tablePanel.setTableColumnHeader(this.hGroup.getColumnId(), this.hGroup.getColumnName());
	tablePanel.setTableColumnHeader(this.hExpireDate.getColumnId(), this.hExpireDate.getColumnName());
	tablePanel.setTableColumnHeader(this.hCommand.getColumnId(), this.hCommand.getColumnName());

	if (tableViewButtons != null && !tableViewButtons.isEmpty()) {
	    for (Button button : tableViewButtons) {
		button.setCaption(this.messageBAO
			.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.view"));
	    }
	}

	if (tableEditButtons != null && !tableEditButtons.isEmpty()) {
	    for (Button button : tableEditButtons) {
		button.setCaption(this.messageBAO
			.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.edit"));
	    }
	}

	if (tableDeleteButtons != null && !tableDeleteButtons.isEmpty()) {
	    for (Button button : tableDeleteButtons) {
		button.setCaption(this.messageBAO
			.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.delete"));
	    }
	}
    }

    @Override
    public void init() {
	this.setSizeFull();

	this.searchBOUserPanel.setSizeFull();
	this.searchBOUserPanel.setId("searchBOUserPanel");

	lblUsername.setWidth("120px");
	lblEmployeeId.setWidth("120px");

	lblEmailAddress.setWidth("120px");
	lblEmployeeName.setWidth("120px");

	lblStatus.setWidth("70px");
	lblGroup.setWidth("70px");

	lblCreateBy.setWidth("120px");
	lblLastUpdateBy.setWidth("120px");

	lblExpireDate.setWidth("120px");
	lblCreateDate.setWidth("120px");
	lblLastUpdateDate.setWidth("120px");

	cbbUsername.setWidth("150px");
	cbbEmployeeId.setWidth("150px");
	cbbEmployeeName.setWidth("150px");
	cbbCreateBy.setWidth("150px");
	cbbLastUpdateBy.setWidth("150px");
	cbbGroup.setWidth("150px");
	cbbStatus.setWidth("150px");

	pdfExpireDateFrom.setWidth("150px");
	pdfExpireDateTo.setWidth("150px");
	pdfCreateDateFrom.setWidth("150px");
	pdfCreateDateTo.setWidth("150px");
	pdfLastUpdateDateFrom.setWidth("150px");
	pdfLastUpdateDateTo.setWidth("150px");

	txtEmailAddress.setWidth("150px");

	this.txtEmailAddress.setMaxLength(200);

	this.cbbUsername.setFilteringMode(FilteringMode.STARTSWITH);
	this.cbbEmployeeId.setFilteringMode(FilteringMode.STARTSWITH);
	this.cbbEmployeeName.setFilteringMode(FilteringMode.STARTSWITH);
	this.cbbCreateBy.setFilteringMode(FilteringMode.STARTSWITH);
	this.cbbLastUpdateBy.setFilteringMode(FilteringMode.STARTSWITH);

	this.cbbUsername.setNewItemsAllowed(true);
	this.cbbEmployeeId.setNewItemsAllowed(true);
	this.cbbEmployeeName.setNewItemsAllowed(true);
	this.cbbCreateBy.setNewItemsAllowed(true);
	this.cbbLastUpdateBy.setNewItemsAllowed(true);

	this.cbbGroup.setNullSelectionAllowed(false);
	this.cbbStatus.setNullSelectionAllowed(false);
	this.cbbGroup.setTextInputAllowed(false);
	this.cbbStatus.setTextInputAllowed(false);

	this.pdfCreateDateFrom.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.pdfCreateDateTo.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.pdfExpireDateFrom.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.pdfExpireDateTo.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.pdfLastUpdateDateFrom.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.pdfLastUpdateDateTo.setDateFormat(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));

	this.pdfCreateDateFrom.setInvalidAllowed(false);
	this.pdfCreateDateTo.setInvalidAllowed(false);
	this.pdfExpireDateFrom.setInvalidAllowed(false);
	this.pdfExpireDateTo.setInvalidAllowed(false);
	this.pdfLastUpdateDateFrom.setInvalidAllowed(false);
	this.pdfLastUpdateDateTo.setInvalidAllowed(false);

	this.btnSearch.addStyleName("button-blue");
	this.btnNew.addStyleName("button-blue");
	this.btnClear.addStyleName("button-green");

	this.btnSearch.setDisableOnClick(true);
	this.btnNew.setDisableOnClick(true);
	this.btnClear.setDisableOnClick(true);

	this.btnSearch.setWidth("70px");
	this.btnNew.setWidth("70px");
	this.btnClear.setWidth("70px");

	this.hUsername.setColumnId("username");
	this.hUsername.setType(String.class);
	this.hUsername.setAlignment(Align.CENTER);
	this.hUsername.setDefaultValue(null);
	this.hUsername.setIconResource(null);
	this.hUsername.setWidth(80);
	this.hUsername.setOrder(1);

	this.hEmployeeId.setColumnId("employeeId");
	this.hEmployeeId.setType(String.class);
	this.hEmployeeId.setAlignment(Align.CENTER);
	this.hEmployeeId.setDefaultValue(null);
	this.hEmployeeId.setIconResource(null);
	this.hEmployeeId.setWidth(80);
	this.hEmployeeId.setOrder(2);

	this.hEmployeeName.setColumnId("employeeName");
	this.hEmployeeName.setType(String.class);
	this.hEmployeeName.setAlignment(Align.LEFT);
	this.hEmployeeName.setDefaultValue(null);
	this.hEmployeeName.setIconResource(null);
	this.hEmployeeName.setOrder(3);

	this.hEmailAddress.setColumnId("emailAddress");
	this.hEmailAddress.setType(String.class);
	this.hEmailAddress.setAlignment(Align.LEFT);
	this.hEmailAddress.setDefaultValue(null);
	this.hEmailAddress.setIconResource(null);
	this.hEmailAddress.setOrder(4);

	this.hGroup.setColumnId("group");
	this.hGroup.setType(String.class);
	this.hGroup.setAlignment(Align.CENTER);
	this.hGroup.setDefaultValue(null);
	this.hGroup.setIconResource(null);
	this.hGroup.setWidth(80);
	this.hGroup.setOrder(5);

	this.hExpireDate.setColumnId("expireDate");
	this.hExpireDate.setType(Date.class);
	this.hExpireDate.setFormatPattern(this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.format.date"));
	this.hExpireDate.setAlignment(Align.CENTER);
	this.hExpireDate.setDefaultValue(null);
	this.hExpireDate.setIconResource(null);
	this.hExpireDate.setWidth(80);
	this.hExpireDate.setOrder(6);

	this.hStatus.setColumnId("status");
	this.hStatus.setType(String.class);
	this.hStatus.setAlignment(Align.CENTER);
	this.hStatus.setDefaultValue(null);
	this.hStatus.setIconResource(null);
	this.hStatus.setWidth(80);
	this.hStatus.setOrder(7);

	this.hCreateDate.setColumnId("createDate");
	this.hCreateDate.setType(String.class);
	this.hCreateDate.setAlignment(Align.CENTER);
	this.hCreateDate.setDefaultValue(null);
	this.hCreateDate.setIconResource(null);
	this.hCreateDate.setWidth(110);
	this.hCreateDate.setOrder(8);

	this.hCreateBy.setColumnId("createBy");
	this.hCreateBy.setType(String.class);
	this.hCreateBy.setAlignment(Align.CENTER);
	this.hCreateBy.setDefaultValue(null);
	this.hCreateBy.setIconResource(null);
	this.hCreateBy.setWidth(90);
	this.hCreateBy.setOrder(9);

	this.hLastUpdateDate.setColumnId("lastUpdateDate");
	this.hLastUpdateDate.setType(String.class);
	this.hLastUpdateDate.setAlignment(Align.CENTER);
	this.hLastUpdateDate.setDefaultValue(null);
	this.hLastUpdateDate.setIconResource(null);
	this.hLastUpdateDate.setWidth(110);
	this.hLastUpdateDate.setOrder(10);

	this.hLastUpdateBy.setColumnId("lastUpdateBy");
	this.hLastUpdateBy.setType(String.class);
	this.hLastUpdateBy.setAlignment(Align.CENTER);
	this.hLastUpdateBy.setDefaultValue(null);
	this.hLastUpdateBy.setIconResource(null);
	this.hLastUpdateBy.setWidth(90);
	this.hLastUpdateBy.setOrder(11);

	this.hCommand.setColumnId("commandLayout");
	this.hCommand.setType(HorizontalLayout.class);
	this.hCommand.setAlignment(Align.CENTER);
	this.hCommand.setDefaultValue(null);
	this.hCommand.setIconResource(null);
	this.hCommand.setWidth(140);
	this.hCommand.setOrder(12);

	List<TableHeaderProperty> headerProperties = new ArrayList<TableHeaderProperty>();
	headerProperties.add(hUsername);
	headerProperties.add(hEmployeeId);
	headerProperties.add(hEmployeeName);
	headerProperties.add(hEmailAddress);
	headerProperties.add(hGroup);
	headerProperties.add(hExpireDate);
	headerProperties.add(hStatus);
	headerProperties.add(hCreateDate);
	headerProperties.add(hCreateBy);
	headerProperties.add(hLastUpdateDate);
	headerProperties.add(hLastUpdateBy);
	headerProperties.add(hCommand);

	this.tablePanel.setTableBeanContainerColumnHeader(headerProperties, SearchBOUserTableItemBean.class);
	this.tablePanel.setTableSelect(false);
	this.tablePanel.setAllowSortRecord(false);
	this.tablePanel.setEnableTableSorting(false);
	this.tablePanel.setTableColumnReordering(false);
	this.tablePanel.createControlTablePageNumber();
	this.tablePanel.setSortingTablePanel(this.sortingTablePanel);

	VerticalLayout mainLayout = new VerticalLayout();
	mainLayout.setSizeFull();
	mainLayout.setSizeUndefined();
	mainLayout.setSpacing(true);
	mainLayout.setWidth("100%");

	this.searchBOUserPanel.setContent(mainLayout);

	VerticalLayout formLayout = new VerticalLayout();
	formLayout.setId("formPanel");
	formLayout.setSizeUndefined();
	formLayout.setWidth("100%");
	formLayout.setSpacing(true);

	HorizontalLayout row0 = new HorizontalLayout();
	HorizontalLayout row1 = new HorizontalLayout();
	HorizontalLayout row2 = new HorizontalLayout();
	HorizontalLayout row3 = new HorizontalLayout();
	HorizontalLayout row4 = new HorizontalLayout();
	HorizontalLayout row5 = new HorizontalLayout();
	HorizontalLayout row6 = new HorizontalLayout();
	HorizontalLayout row7 = new HorizontalLayout();
	HorizontalLayout row8 = new HorizontalLayout();

	row1.setSpacing(true);
	row2.setSpacing(true);
	row3.setSpacing(true);
	row4.setSpacing(true);
	row5.setSpacing(true);
	row6.setSpacing(true);
	row7.setSpacing(true);
	row8.setSpacing(true);

	row1.setSizeUndefined();
	row2.setSizeUndefined();
	row3.setSizeUndefined();
	row4.setSizeUndefined();
	row5.setSizeUndefined();
	row6.setSizeUndefined();
	row7.setSizeUndefined();
	row8.setSizeUndefined();

	HorizontalLayout row1Col1 = new HorizontalLayout();
	HorizontalLayout row1Sep1 = new HorizontalLayout();
	HorizontalLayout row1Col2 = new HorizontalLayout();
	HorizontalLayout row1Sep2 = new HorizontalLayout();
	HorizontalLayout row1Col3 = new HorizontalLayout();

	row1Col1.setSpacing(true);
	row1Col2.setSpacing(true);
	row1Col3.setSpacing(true);

	row1Sep1.setWidth("25px");
	row1Sep2.setWidth("25px");

	row1Col1.addComponent(lblUsername);
	row1Col1.addComponent(cbbUsername);
	row1Col2.addComponent(lblEmailAddress);
	row1Col2.addComponent(txtEmailAddress);
	row1Col3.addComponent(lblStatus);
	row1Col3.addComponent(cbbStatus);

	row1Col1.setComponentAlignment(lblUsername, Alignment.MIDDLE_LEFT);
	row1Col1.setComponentAlignment(cbbUsername, Alignment.MIDDLE_LEFT);
	row1Col2.setComponentAlignment(lblEmailAddress, Alignment.MIDDLE_LEFT);
	row1Col2.setComponentAlignment(txtEmailAddress, Alignment.MIDDLE_LEFT);
	row1Col3.setComponentAlignment(lblStatus, Alignment.MIDDLE_LEFT);
	row1Col3.setComponentAlignment(cbbStatus, Alignment.MIDDLE_LEFT);

	row1.addComponent(row1Col1);
	row1.addComponent(row1Sep1);
	row1.addComponent(row1Col2);
	row1.addComponent(row1Sep2);
	row1.addComponent(row1Col3);

	HorizontalLayout row2Col1 = new HorizontalLayout();
	HorizontalLayout row2Sep1 = new HorizontalLayout();
	HorizontalLayout row2Col2 = new HorizontalLayout();
	HorizontalLayout row2Sep2 = new HorizontalLayout();
	HorizontalLayout row2Col3 = new HorizontalLayout();

	row2Sep1.setWidth("25px");
	row2Sep2.setWidth("25px");

	row2Col1.setSpacing(true);
	row2Col2.setSpacing(true);
	row2Col3.setSpacing(true);

	row2Col1.addComponent(lblEmployeeId);
	row2Col1.addComponent(cbbEmployeeId);
	row2Col2.addComponent(lblEmployeeName);
	row2Col2.addComponent(cbbEmployeeName);
	row2Col3.addComponent(lblGroup);
	row2Col3.addComponent(cbbGroup);

	row2Col1.setComponentAlignment(lblEmployeeId, Alignment.MIDDLE_LEFT);
	row2Col1.setComponentAlignment(cbbEmployeeId, Alignment.MIDDLE_LEFT);
	row2Col2.setComponentAlignment(lblEmployeeName, Alignment.MIDDLE_LEFT);
	row2Col2.setComponentAlignment(cbbEmployeeName, Alignment.MIDDLE_LEFT);
	row2Col3.setComponentAlignment(lblGroup, Alignment.MIDDLE_LEFT);
	row2Col3.setComponentAlignment(cbbGroup, Alignment.MIDDLE_LEFT);

	row2.addComponent(row2Col1);
	row2.addComponent(row2Sep1);
	row2.addComponent(row2Col2);
	row2.addComponent(row2Sep2);
	row2.addComponent(row2Col3);

	HorizontalLayout row3Col1 = new HorizontalLayout();
	HorizontalLayout row3Sep1 = new HorizontalLayout();
	HorizontalLayout row3Col2 = new HorizontalLayout();
	HorizontalLayout row3Sep2 = new HorizontalLayout();
	HorizontalLayout row3Col3 = new HorizontalLayout();

	row3Col1.setSpacing(true);
	row3Col2.setSpacing(true);
	row3Col3.setSpacing(true);

	row3Col3.setWidth("232px");
	row3Sep1.setWidth("25px");
	row3Sep2.setWidth("25px");

	row3Col1.addComponent(lblCreateBy);
	row3Col1.addComponent(cbbCreateBy);
	row3Col2.addComponent(lblLastUpdateBy);
	row3Col2.addComponent(cbbLastUpdateBy);

	row3Col1.setComponentAlignment(lblCreateBy, Alignment.MIDDLE_LEFT);
	row3Col1.setComponentAlignment(cbbCreateBy, Alignment.MIDDLE_LEFT);
	row3Col2.setComponentAlignment(lblLastUpdateBy, Alignment.MIDDLE_LEFT);
	row3Col2.setComponentAlignment(cbbLastUpdateBy, Alignment.MIDDLE_LEFT);

	row3.addComponent(row3Col1);
	row3.addComponent(row3Sep1);
	row3.addComponent(row3Col2);
	row3.addComponent(row3Sep2);
	row3.addComponent(row3Col3);

	HorizontalLayout row4Col1 = new HorizontalLayout();
	HorizontalLayout row4Sep1 = new HorizontalLayout();
	HorizontalLayout row4Col2 = new HorizontalLayout();
	HorizontalLayout row4Sep2 = new HorizontalLayout();
	HorizontalLayout row4Col3 = new HorizontalLayout();

	row4Col1.setSpacing(true);
	row4Col2.setSpacing(true);
	row4Col3.setSpacing(true);

	row4Sep1.setWidth("25px");
	row4Sep2.setWidth("25px");

	row4Col1.addComponent(lblExpireDate);
	row4Col2.addComponent(lblExpireDateFrom);
	row4Col2.addComponent(pdfExpireDateFrom);
	row4Col3.addComponent(lblExpireDateTo);
	row4Col3.addComponent(pdfExpireDateTo);

	row4Col1.setComponentAlignment(lblExpireDate, Alignment.MIDDLE_LEFT);
	row4Col2.setComponentAlignment(lblExpireDateFrom, Alignment.MIDDLE_LEFT);
	row4Col2.setComponentAlignment(pdfExpireDateFrom, Alignment.MIDDLE_LEFT);
	row4Col3.setComponentAlignment(lblExpireDateTo, Alignment.MIDDLE_LEFT);
	row4Col3.setComponentAlignment(pdfExpireDateTo, Alignment.MIDDLE_LEFT);

	row4.addComponent(row4Col1);
	row4.addComponent(row4Sep1);
	row4.addComponent(row4Col2);
	row4.addComponent(row4Sep2);
	row4.addComponent(row4Col3);

	HorizontalLayout row5Col1 = new HorizontalLayout();
	HorizontalLayout row5Sep1 = new HorizontalLayout();
	HorizontalLayout row5Col2 = new HorizontalLayout();
	HorizontalLayout row5Sep2 = new HorizontalLayout();
	HorizontalLayout row5Col3 = new HorizontalLayout();

	row5Col1.setSpacing(true);
	row5Col2.setSpacing(true);
	row5Col3.setSpacing(true);

	row5Sep1.setWidth("25px");
	row5Sep2.setWidth("25px");

	row5Col1.addComponent(lblCreateDate);
	row5Col2.addComponent(lblCreateDateFrom);
	row5Col2.addComponent(pdfCreateDateFrom);
	row5Col3.addComponent(lblCreateDateTo);
	row5Col3.addComponent(pdfCreateDateTo);

	row5Col1.setComponentAlignment(lblCreateDate, Alignment.MIDDLE_LEFT);
	row5Col2.setComponentAlignment(lblCreateDateFrom, Alignment.MIDDLE_LEFT);
	row5Col2.setComponentAlignment(pdfCreateDateFrom, Alignment.MIDDLE_LEFT);
	row5Col3.setComponentAlignment(lblCreateDateTo, Alignment.MIDDLE_LEFT);
	row5Col3.setComponentAlignment(pdfCreateDateTo, Alignment.MIDDLE_LEFT);

	row5.addComponent(row5Col1);
	row5.addComponent(row5Sep1);
	row5.addComponent(row5Col2);
	row5.addComponent(row5Sep2);
	row5.addComponent(row5Col3);

	HorizontalLayout row6Col1 = new HorizontalLayout();
	HorizontalLayout row6Sep1 = new HorizontalLayout();
	HorizontalLayout row6Col2 = new HorizontalLayout();
	HorizontalLayout row6Sep2 = new HorizontalLayout();
	HorizontalLayout row6Col3 = new HorizontalLayout();

	row6Col1.setSpacing(true);
	row6Col2.setSpacing(true);
	row6Col3.setSpacing(true);

	row6Sep1.setWidth("25px");
	row6Sep2.setWidth("25px");

	row6Col1.addComponent(lblLastUpdateDate);
	row6Col2.addComponent(lblLastUpdateDateFrom);
	row6Col2.addComponent(pdfLastUpdateDateFrom);
	row6Col3.addComponent(lblLastUpdateDateTo);
	row6Col3.addComponent(pdfLastUpdateDateTo);

	row6Col1.setComponentAlignment(lblLastUpdateDate, Alignment.MIDDLE_LEFT);
	row6Col2.setComponentAlignment(lblLastUpdateDateFrom, Alignment.MIDDLE_LEFT);
	row6Col2.setComponentAlignment(pdfLastUpdateDateFrom, Alignment.MIDDLE_LEFT);
	row6Col3.setComponentAlignment(lblLastUpdateDateTo, Alignment.MIDDLE_LEFT);
	row6Col3.setComponentAlignment(pdfLastUpdateDateTo, Alignment.MIDDLE_LEFT);

	row6.addComponent(row6Col1);
	row6.addComponent(row6Sep1);
	row6.addComponent(row6Col2);
	row6.addComponent(row6Sep2);
	row6.addComponent(row6Col3);

	row8.addComponent(btnSearch);
	row8.addComponent(btnNew);
	row8.addComponent(btnClear);

	formLayout.addComponent(row0);
	formLayout.addComponent(row1);
	formLayout.addComponent(row2);
	formLayout.addComponent(row3);
	formLayout.addComponent(row4);
	formLayout.addComponent(row5);
	formLayout.addComponent(row6);
	formLayout.addComponent(row7);
	formLayout.addComponent(row8);

	formLayout.setComponentAlignment(row1, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row2, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row3, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row4, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row5, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row6, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row7, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row8, Alignment.MIDDLE_CENTER);

	HorizontalLayout tableSortingLayout = new HorizontalLayout();
	tableSortingLayout.setSizeUndefined();
	tableSortingLayout.setWidth("99%");
	tableSortingLayout.addComponent(this.sortingTablePanel);

	HorizontalLayout tableLayout = new HorizontalLayout();
	tableLayout.setSizeUndefined();
	tableLayout.setWidth("99%");
	tableLayout.addComponent(this.tablePanel);

	mainLayout.addComponent(formLayout);
	mainLayout.addComponent(tableSortingLayout);
	mainLayout.addComponent(tableLayout);
	mainLayout.setExpandRatio(tableLayout, 1);

	mainLayout.setComponentAlignment(formLayout, Alignment.MIDDLE_CENTER);
	mainLayout.setComponentAlignment(tableSortingLayout, Alignment.MIDDLE_CENTER);
	mainLayout.setComponentAlignment(tableLayout, Alignment.MIDDLE_CENTER);

	this.addComponent(this.searchBOUserPanel);
	this.setComponentAlignment(this.searchBOUserPanel, Alignment.TOP_CENTER);

    }

    @Override
    public void initListener() {
	this.searchBOUserClearButtonClickListener.setBasedComponent(this);
	this.searchBOUserNewButtonClickListener.setBasedComponent(this);
	this.searchBOUserSearchButtonClickListener.setBasedComponent(this);
	this.searchBOUserTableDeleteButtonClickListener.setBasedComponent(this);
	this.searchBOUserTableEditButtonClickListener.setBasedComponent(this);
	this.searchBOUserTablePageButtonClickListener.setBasedComponent(this);
	this.searchBOUserTableSizeValueChangeListener.setBasedComponent(this);
	this.searchBOUserTableSortButtonClickListener.setBasedComponent(this);
	this.searchBOUserTableViewButtonClickListener.setBasedComponent(this);

	this.searchBOUserClearButtonClickListener.setAutoEnabled(true);
	this.searchBOUserNewButtonClickListener.setAutoEnabled(true);
	this.searchBOUserSearchButtonClickListener.setAutoEnabled(true);
	this.searchBOUserTableViewButtonClickListener.setAutoEnabled(true);
	this.searchBOUserTableDeleteButtonClickListener.setAutoEnabled(true);
	this.searchBOUserTableEditButtonClickListener.setAutoEnabled(true);

	this.searchBOUserTablePageButtonClickListener.setTablePanel(this.tablePanel);
	this.searchBOUserTableSizeValueChangeListener.setTablePanel(this.tablePanel);
	this.searchBOUserTableSortButtonClickListener.setTablePanel(this.tablePanel);

	this.tablePanel.addPageTableButtonClickListener(this.searchBOUserTablePageButtonClickListener);
	this.tablePanel.addSizeTableValueChangeListener(this.searchBOUserTableSizeValueChangeListener);
	this.sortingTablePanel.addSortTableButtonClickListener(this.searchBOUserTableSortButtonClickListener);

	this.btnSearch.addClickListener(this.searchBOUserSearchButtonClickListener);
	this.btnNew.addClickListener(this.searchBOUserNewButtonClickListener);
	this.btnClear.addClickListener(this.searchBOUserClearButtonClickListener);
    }

    @Override
    public void initValidator() {

    }

    @SuppressWarnings("rawtypes")
    @Override
    public void initData() {
	try {
	    String sortingDefault = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.default.table.sorting");
	    String sortingItem = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.table.sorting.item");
	    String sortingCaption = this.messageBAO
		    .getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.table.sorting.caption");

	    if (sortingItem != null) {
		String[] sortingItemArr = sortingItem.split(",");
		String[] sortingCaptionArr = sortingCaption.split(",");
		if (sortingItemArr != null) {
		    for (int loop = 0; loop < sortingItemArr.length; loop++) {
			this.sortingTablePanel.addSortingItem(sortingItemArr[loop], sortingCaptionArr[loop]);
		    }
		}
	    }

	    String groupDefault = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.default.group.item");
	    String groupInclude = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.include.group.item");
	    String groupIncludeCaption = this.messageBAO
		    .getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.include.group.item.caption");
	    if (groupInclude != null) {
		String[] groupIncludeArr = groupInclude.split(",");
		String[] groupIncludeCaptionArr = groupIncludeCaption.split(",");
		if (groupIncludeArr != null) {
		    for (int loop = 0; loop < groupIncludeArr.length; loop++) {
			this.cbbGroup.addItem(groupIncludeArr[loop]);
			this.cbbGroup.setItemCaption(groupIncludeArr[loop], groupIncludeCaptionArr[loop]);
		    }
		}
	    }
	    List<EntryBean<Long, String>> roles = this.masterDataBAO.selectAllBOUserRole();
	    if (roles != null) {
		for (EntryBean<Long, String> entry : roles) {
		    this.cbbGroup.addItem(entry.getValue());
		    this.cbbGroup.setItemCaption(entry.getValue(), entry.getValue());
		}
	    }
	    this.cbbGroup.select(groupDefault);
	    this.cbbGroup.setValue(groupDefault);

	    String statusDefault = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.default.status.item");
	    String statusInclude = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.include.status.item");
	    String statusExclude = this.propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.exclude.status.item");
	    String statusIncludeCaption = this.messageBAO
		    .getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.include.status.item.caption");
	    if (statusInclude != null) {
		String[] statusIncludeArr = statusInclude.split(",");
		String[] statusIncludeCaptionArr = statusIncludeCaption.split(",");
		if (statusIncludeArr != null) {
		    for (int loop = 0; loop < statusIncludeArr.length; loop++) {
			this.cbbStatus.addItem(statusIncludeArr[loop]);
			this.cbbStatus.setItemCaption(statusIncludeArr[loop], statusIncludeCaptionArr[loop]);
		    }
		}
	    }
	    List<String> excludes = new ArrayList<String>();
	    if (statusExclude != null) {
		String[] statusExcludeArr = statusExclude.split(",");
		if (statusExcludeArr != null) {
		    for (int loop = 0; loop < statusExcludeArr.length; loop++) {
			excludes.add(statusExcludeArr[loop]);
		    }
		}
	    }
	    List<EntryBean<String, String>> userStatus = this.masterDataBAO.selectAllBOUserStatus();
	    if (userStatus != null) {
		for (EntryBean<String, String> entry : userStatus) {
		    this.statusMap.put(entry.getKey(), entry.getValue());
		    if (!excludes.contains(entry.getKey())) {
			this.cbbStatus.addItem(entry.getKey());
			this.cbbStatus.setItemCaption(entry.getKey(), entry.getValue());
		    }
		}
	    }
	    this.cbbStatus.select(statusDefault);
	    this.cbbStatus.setValue(statusDefault);

	    List<EntryBean<Long, String>> userEmployeeName = this.masterDataBAO.selectAllBOUserEmployeeName();
	    if (userEmployeeName != null) {
		for (EntryBean<Long, String> entry : userEmployeeName) {
		    if (entry.getValue() != null && entry.getValue().trim().length() > 0) {
			this.cbbEmployeeName.addItem(entry.getValue());
			this.cbbEmployeeName.setItemCaption(entry.getValue(), entry.getValue());
		    }
		}
	    }

	    List<EntryBean<Long, String>> userEmployeeId = this.masterDataBAO.selectAllBOUserEmployeeId();
	    if (userEmployeeId != null) {
		for (EntryBean<Long, String> entry : userEmployeeId) {
		    if (entry.getValue() != null && entry.getValue().trim().length() > 0) {
			this.cbbEmployeeId.addItem(entry.getValue());
			this.cbbEmployeeId.setItemCaption(entry.getValue(), entry.getValue());
		    }
		}
	    }

	    List<EntryBean<Long, String>> userUsername = this.masterDataBAO.selectAllBOUserUsername();
	    if (userUsername != null) {
		for (EntryBean<Long, String> entry : userUsername) {
		    if (entry.getValue() != null && entry.getValue().trim().length() > 0) {
			this.cbbUsername.addItem(entry.getValue());
			this.cbbUsername.setItemCaption(entry.getValue(), entry.getValue());
		    }
		}
	    }

	    List<EntryBean<String, String>> userCreateBy = this.masterDataBAO.selectAllBOUserCreateBy();
	    if (userCreateBy != null) {
		for (EntryBean<String, String> entry : userCreateBy) {
		    if (entry.getValue() != null && entry.getValue().trim().length() > 0) {
			this.cbbCreateBy.addItem(entry.getValue());
			this.cbbCreateBy.setItemCaption(entry.getValue(), entry.getValue());
		    }
		}
	    }

	    List<EntryBean<String, String>> userLastUpdateBy = this.masterDataBAO.selectAllBOUserLastUpdateBy();
	    if (userLastUpdateBy != null) {
		for (EntryBean<String, String> entry : userLastUpdateBy) {
		    if (entry.getValue() != null && entry.getValue().trim().length() > 0) {
			this.cbbLastUpdateBy.addItem(entry.getValue());
			this.cbbLastUpdateBy.setItemCaption(entry.getValue(), entry.getValue());
		    }
		}
	    }

	    searchCriteriaBean.setDirection1(SearchCriteriaBean.DIRECTION_DESC);
	    searchCriteriaBean.setOrder1(sortingDefault);
	    searchCriteriaBean.setCriteriaBean(searchBOUserBean);
	    searchCriteriaBean.setPage(1);
	    searchCriteriaBean.setSize(30);
	    SearchResultBean<BOUserBean> searchResultBean = boUserBAO.selectBOUser(searchCriteriaBean);

	    Integer totalPage = searchResultBean.getTotalPages();
	    if (totalPage == null) {
		totalPage = 1;
	    }
	    Long totalElement = searchResultBean.getTotalElements();
	    if (totalElement == null) {
		totalElement = 0l;
	    }
	    List<BeanItem> beanItems = this.generateTableItemBean(searchResultBean);

	    this.tablePanel.clearTableData();
	    this.tablePanel.setManualPageTable(1);
	    this.tablePanel.setTableBeanContainerDataTotalPage(beanItems, totalPage, totalElement);
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    @SuppressWarnings("rawtypes")
    public List<BeanItem> generateTableItemBean(SearchResultBean<BOUserBean> searchResultBean) {
	List<BeanItem> beanItems = new ArrayList<BeanItem>();
	if (searchResultBean != null && searchResultBean.getContent() != null) {

	    this.tableViewButtons.clear();
	    this.tableEditButtons.clear();
	    this.tableDeleteButtons.clear();

	    DateFormat dateFormat = new SimpleDateFormat(StringUtils.PATTERN_DATE_PERSISTENCE);
	    DateFormat dateTimeFormat = new SimpleDateFormat(StringUtils.PATTERN_DATETIME_PERSISTENCE);
	    DateFormat dateFormatUI = new SimpleDateFormat(StringUtils.PATTERN_DATE_UI);
	    DateFormat dateTimeFormatUI = new SimpleDateFormat(StringUtils.PATTERN_DATETIME_UI);

	    String activeStatus = propertyBAO
		    .getPropertyValue("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.exclude.status.item.active");

	    for (int loop = 0; loop < searchResultBean.getContent().size(); loop++) {
		BOUserBean boUserBean = searchResultBean.getContent().get(loop);
		SearchBOUserTableItemBean searchBOUserTableItemBean = new SearchBOUserTableItemBean();
		searchBOUserTableItemBean.setId(boUserBean.getId());
		searchBOUserTableItemBean.setUsername(boUserBean.getUsername());
		searchBOUserTableItemBean.setEmployeeId(boUserBean.getEmployeeID());
		searchBOUserTableItemBean.setEmployeeName(boUserBean.getEmployeeName());
		searchBOUserTableItemBean.setEmailAddress(boUserBean.getEmail());
		searchBOUserTableItemBean.setGroup(boUserBean.getRole());
		// searchBOUserTableItemBean.setExpireDate(boUserBean.getExpiredDate());
		if (boUserBean.getExpiredDate() != null) {
		    try {
			Date date = dateFormat.parse(boUserBean.getExpiredDate());
			String strUI = dateFormatUI.format(date);
			searchBOUserTableItemBean.setExpireDate(strUI);
		    } catch (ParseException e) {
		    }
		}

		String statusText = this.statusMap.get(boUserBean.getStatus());
		if (statusText == null) {
		    statusText = boUserBean.getStatus();
		}
		searchBOUserTableItemBean.setStatus(statusText);

		if (boUserBean.getCreateDatetime() != null) {
		    try {
			Date date = dateTimeFormat.parse(boUserBean.getCreateDatetime());
			String strUI = dateTimeFormatUI.format(date);
			searchBOUserTableItemBean.setCreateDate(strUI);
		    } catch (ParseException e) {
		    }
		}
		if (boUserBean.getLastUpdateDatetime() != null) {
		    try {
			Date date = dateTimeFormat.parse(boUserBean.getLastUpdateDatetime());
			String strUI = dateTimeFormatUI.format(date);
			searchBOUserTableItemBean.setLastUpdateDate(strUI);
		    } catch (ParseException e) {
		    }
		}

		searchBOUserTableItemBean.setCreateBy(boUserBean.getCreateBy());
		searchBOUserTableItemBean.setLastUpdateBy(boUserBean.getLastUpdateBy());

		HorizontalLayout hLayout = new HorizontalLayout();
		Button btnView = new Button(
			this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.view"));
		Button btnEdit = new Button(
			this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.edit"));
		Button btnDelete = new Button(
			this.messageBAO.getMessage("com.fw.ui.view.settings.usercontrol.bouser.SearchBOUserView.button.table.delete"));

		btnView.setData(boUserBean);
		btnEdit.setData(boUserBean);
		btnDelete.setData(boUserBean);

		btnView.addClickListener(this.searchBOUserTableViewButtonClickListener);
		btnEdit.addClickListener(this.searchBOUserTableEditButtonClickListener);
		btnDelete.addClickListener(this.searchBOUserTableDeleteButtonClickListener);

		btnView.setDisableOnClick(true);
		btnEdit.setDisableOnClick(true);
		btnDelete.setDisableOnClick(true);

		btnView.addStyleName("button-green-small");
		btnEdit.addStyleName("button-blue-small");
		btnDelete.addStyleName("button-red-small");

		if (!activeStatus.equals(boUserBean.getStatus())) {
		    btnDelete.setEnabled(false);
		}

		tableViewButtons.add(btnView);
		tableEditButtons.add(btnEdit);
		tableDeleteButtons.add(btnDelete);

		hLayout.addComponent(btnView);
		hLayout.addComponent(new Label("&nbsp;", ContentMode.HTML));
		hLayout.addComponent(btnEdit);
		hLayout.addComponent(new Label("&nbsp;", ContentMode.HTML));
		hLayout.addComponent(btnDelete);

		searchBOUserTableItemBean.setCommandLayout(hLayout);

		beanItems.add(new BeanItem<SearchBOUserTableItemBean>(searchBOUserTableItemBean));
	    }
	}
	return beanItems;
    }

    public TablePanel getTablePanel() {
	return tablePanel;
    }

    public SortingTablePanel getSortingTablePanel() {
	return sortingTablePanel;
    }

    public ComboBox getCbbUsername() {
	return cbbUsername;
    }

    public ComboBox getCbbEmployeeId() {
	return cbbEmployeeId;
    }

    public ComboBox getCbbEmployeeName() {
	return cbbEmployeeName;
    }

    public ComboBox getCbbCreateBy() {
	return cbbCreateBy;
    }

    public ComboBox getCbbLastUpdateBy() {
	return cbbLastUpdateBy;
    }

    public ComboBox getCbbGroup() {
	return cbbGroup;
    }

    public ComboBox getCbbStatus() {
	return cbbStatus;
    }

    public TextField getTxtEmailAddress() {
	return txtEmailAddress;
    }

    public PopupDateField getPdfExpireDateFrom() {
	return pdfExpireDateFrom;
    }

    public PopupDateField getPdfExpireDateTo() {
	return pdfExpireDateTo;
    }

    public PopupDateField getPdfCreateDateFrom() {
	return pdfCreateDateFrom;
    }

    public PopupDateField getPdfCreateDateTo() {
	return pdfCreateDateTo;
    }

    public PopupDateField getPdfLastUpdateDateFrom() {
	return pdfLastUpdateDateFrom;
    }

    public PopupDateField getPdfLastUpdateDateTo() {
	return pdfLastUpdateDateTo;
    }

    public Button getBtnSearch() {
	return btnSearch;
    }

    public Button getBtnNew() {
	return btnNew;
    }

    public Button getBtnClear() {
	return btnClear;
    }

    public SearchCriteriaBean<SearchBOUserBean> getSearchCriteriaBean() {
	return searchCriteriaBean;
    }

    public void setSearchCriteriaBean(SearchCriteriaBean<SearchBOUserBean> searchCriteriaBean) {
	this.searchCriteriaBean = searchCriteriaBean;
    }

}
